<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>商品列表</title>
    <link href="__STATIC__/admin/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="__STATIC__/admin/css/style.css"/>
    <link href="__STATIC__/admin/assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="__STATIC__/admin/font/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="__STATIC__/admin/js/jquery-1.9.1.min.js"></script>
    <script src="__STATIC__/admin/assets/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__STATIC__/admin/Widget/Validform/5.3.2/Validform.min.js"></script>
    <script src="__STATIC__/admin/assets/js/typeahead-bs2.min.js"></script>
    <script src="__STATIC__/admin/assets/js/jquery.dataTables.min.js"></script>
    <script src="__STATIC__/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="__STATIC__/admin/assets/layer/layer.js" type="text/javascript"></script>
    <script src="__STATIC__/admin/js/lrtk.js" type="text/javascript"></script>
    <script src="__STATIC__/admin/assets/layer/layer.js" type="text/javascript"></script>
    <script src="__STATIC__/admin/assets/laydate/laydate.js" type="text/javascript"></script>
</head>

<body>
<div class="crumbs">
    <ul>
        <li>
            <a class="active" href="javascript:;">商品列表</a>
        </li>
    </ul>
</div>
<div class="page-content clearfix">
    <div class="administrator">
        <div class="d_Confirm_Order_style">
            <form action="{:url('product/index')}" method="get">
                <div class="search_style">
                    <ul class="search_content clearfix">
                        <li>
                            <label class="l_f">输入搜索关键字:</label>
                            <input name="keyword" type="text" class="text_add"
                                   placeholder="商品名称、upc搜索"
                                   value=""/>
                        </li>

                        <li style="width:90px;">
                            <button type="submit" class="btn_search">
                                <i class="fa fa-search"></i>查询
                            </button>
                        </li>
                    </ul>
                </div>
            </form>
            <!--操作-->
            <div class="border clearfix">
                <span class="l_f">
                    <a href="javascript:;" class="btn btn-warning"><i class="fa fa-plus"></i> 添加管理员</a>
                    <a href="javascript:;" class="btn btn-danger" id="delMultip"><i class="fa fa-trash"></i> 批量删除</a>
                </span>
            </div>
            <!--管理员列表-->
            <div class="clearfix">
                <div class="table_menu_list">
                    <form id="form1" action="{:url('rbac/deladministrator')}" method="post">
                        <table class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th width="25px">
                                    <label>
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </th>
                                <th width="80px">编号</th>
                                <th width="250px">商品名称</th>
                                <th width="100px">upc</th>
                                <th width="100px">库存</th>
                                <th width="180px">价格</th>
                                <th width="70px">原价</th>
                                <th width="70px">类别</th>
                                <th width="70px">添加时间</th>
                                <th width="200px">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach $product_list as $item}
                            <tr>
                                <td>
                                    <label>
                                        <input type="checkbox" class="ace del_admin" name="ids[]"
                                               value="{$item.id}">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{$item.id}</td>
                                <td>{$item.title}</td>
                                <td>{$item.upc}</td>
                                <td>{$item.quantity}</td>
                                <td>{$item.price}</td>
                                <td>{$item.price_origin}</td>
                                <td>{$item.category_id}</td>
                                <td>{$item.create_time}</td>
                                <td>
                                    <a title="相册" href="{:url('product/photo',['id'=>$item.id])}"
                                       class="btn btn-xs btn-info">相册</a>
                                    <a title="编辑" href="{:url('product/set',['id'=>$item.id])}"
                                       class="btn btn-xs btn-info">
                                        <i class="fa fa-edit bigger-120"></i>
                                    </a>
                                    <a title="删除" href="javascript:;" data-id="{$item.id}"
                                       class="btn btn-xs btn-warning administrator_del">
                                        <i class="fa fa-trash  bigger-120"></i>
                                    </a>
                                </td>
                            </tr>
                            {/foreach}

                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="dataTables_info">{$product_list->render()}</div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        //单行删除
        $('.administrator_del').on('click', function () {
            //声明变量存储用户当前单击的超链接
            var that = $(this);
            //询问是否删除
            layer.confirm('真的那么狠心啊?', {icon: 3, title: '删除提示'}, function (index) {
                del(that);
                layer.close(index);
            });
        })

        function del(that) {
            var admin_id = $(that).data('id');
            var url = "{:url('rbac/delAdministrator')}";
            var data = {admin_id: admin_id, is_row: true};
            $.post(url, data, function (res) {
                if (res.status == 1) {
                    //删除表格上的行
                    $(that).parent().parent().remove();
                    layer.msg('删除成功', {
                        title: '提示',
                        icon: 6
                    });
                } else {
                    layer.msg('删除失败', {
                        title: '提示',
                        icon: 4
                    });
                }
            }, 'json')
        }

        //多行删除
        $('#delMultip').on('click', function () {
            //判断用户是否选中
            var num = 0;
            $.each($('.del_admin'), function (index, item) {
                if (item.checked) {
                    num++;
                }
            })
            if (num==0){
                layer.msg('您没有选择任何要删除的数据');
                return;
            }
            layer.confirm("真的那么狠心吗?", {icon: 3, title: '删除提示'}, function (index) {
                $('#form1').submit();
            })
        })

        $(function () {
            $('table th input:checkbox').on('click', function () {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox').each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
            });
            laydate({
                elem: '#start',
                event: 'focus'
            });
        })

        /*用户-停用*/
        function member_stop(obj, id) {
            layer.confirm('确认要停用吗？', function (index) {
                $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="fa fa-close bigger-120"></i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
                $(obj).remove();
                layer.msg('已停用!', {
                    icon: 5,
                    time: 1000
                });
            });
        }

        /*用户-启用*/
        function member_start(obj, id) {
            layer.confirm('确认要启用吗？', function (index) {
                $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="fa fa-check  bigger-120"></i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                $(obj).remove();
                layer.msg('已启用!', {
                    icon: 6,
                    time: 1000
                });
            });
        }
    </script>
</body>
</html>